package org.mall.modules.shoptype.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.mall.modules.shoptype.entity.ShopType;
import org.mall.modules.shoptype.entity.ShopTypeNameDTO;
import org.mall.modules.shoptype.mapper.ShopTypeMapper;
import org.mall.modules.shoptype.service.IShopTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * @Description: 商品类目/商户类型
 * @Author: jeecg-boot
 * @Date:   2019-10-30
 * @Version: V1.0
 */
@Service
public class ShopTypeServiceImpl extends ServiceImpl<ShopTypeMapper, ShopType> implements IShopTypeService {

    @Autowired
    private ShopTypeMapper shopTypeMapper;

    @Override
    public IPage<ShopType> list(Page<ShopType> page, QueryWrapper<ShopType> queryWrapper) {
        return shopTypeMapper.getNodeTree(page,queryWrapper);
    }

    @Override
    public List<ShopType> getShopTypeList(Integer type) {
        return shopTypeMapper.getShopTypeList(type);
    }

    @Override
    public List<ShopType> getShopTypeListByName(String name) {
        return shopTypeMapper.getShopTypeListByName(name);
    }

    @Override
    public List<ShopType> getShopTypeListByTypeAndLevel(Integer type, Integer level) {
        QueryWrapper<ShopType> queryWrapper=new QueryWrapper<>();
        ShopType query=new ShopType();
        query.setLevel(level);
        query.setType(type);
        return shopTypeMapper.selectList(queryWrapper);
    }


    @Override
    public List<ShopType> getShopTypeListByParentId(Integer id) {

        QueryWrapper<ShopType> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("parent_id",id);

        return shopTypeMapper.selectList(queryWrapper);

    }

    @Override
    public List<ShopType> getShopTypeListOfNoTree(Integer i) {
        return shopTypeMapper.getShopTypeListOfNoTree(i);
    }

    @Override
    public List<ShopType> getGoodsTypeListByShopId(String shopId) {
        return shopTypeMapper.getGoodsTypeListByShopId(shopId);
    }

    @Override
    public List<ShopType> getGoodsTypeListOfFirstLevel() {
        return shopTypeMapper.getGoodsTypeListOfFirstLevel();
    }

    @Override
    public List<ShopTypeNameDTO> getGoodSTypeNameList(List<String> shopids) {
        if (shopids==null||shopids.isEmpty()){
            return Collections.emptyList();
        }
        return shopTypeMapper.getGoodSTypeNameList(shopids);
    }

}
